<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="公司名称" prop="xxmc">
        <el-input
          v-model="queryParams.xxmc"
          placeholder="请输入公司名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合作方电话" prop="hzfdh" label-width="120">
        <el-input
          v-model="queryParams.hzfdh"
          placeholder="请输入合作方电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合作方税号" prop="hzfsh" label-width="120">
        <el-input
          v-model="queryParams.hzfsh"
          placeholder="请输入合作方税号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经办人" prop="jbr">
        <el-input
          v-model="queryParams.jbr"
          placeholder="请输入经办人"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="合作方名称" prop="hzfmc" label-width="120">
        <el-input
          v-model="queryParams.hzfmc"
          placeholder="请输入合作方名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:cooperManage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:cooperManage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:cooperManage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:cooperManage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cooperManageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司代码" align="center" prop="xxdm" />
      <el-table-column label="公司名称" align="center" prop="xxmc" />
      <el-table-column label="合作方电话" align="center" prop="hzfdh" />
      <el-table-column label="合作方税号" align="center" prop="hzfsh" />
      <el-table-column label="合作方开户行" align="center" prop="hzfkhx" />
      <el-table-column label="合作方账号" align="center" prop="hzfzh" />
      <el-table-column label="邮编" align="center" prop="yb" />
      <el-table-column label="合作方服务人员" align="center" prop="hzffwry" />
      <el-table-column label="建档日期" align="center" prop="jdrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.jdrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合作方合同/协议" align="center" prop="hzfht" />
      <el-table-column label="主要内容" align="center" prop="zynr" />
      <el-table-column label="合同情况" align="center" prop="htqk" />
      <el-table-column label="合作方类别" align="center" prop="hzflb" />
      <el-table-column label="合同变更情况及附件" align="center" prop="htbgqkjfj" />
      <el-table-column label="合作项目编号" align="center" prop="hzxmbh" />
      <el-table-column label="合作项目名称" align="center" prop="hzxmmc" />
      <el-table-column label="合作方资金往来类别" align="center" prop="hzfzjwllb" />
      <el-table-column label="资金金额" align="center" prop="zjje" />
      <el-table-column label="经办人" align="center" prop="jbr" />
      <el-table-column label="创建人" align="center" prop="cjr" />
      <el-table-column label="创建日期" align="center" prop="cjrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.cjrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改人" align="center" prop="xgr" />
      <el-table-column label="合作方类型" align="center" prop="hzflx" />
      <el-table-column label="修改日期" align="center" prop="xgrq" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.xgrq, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合作方代码" align="center" prop="hzfdm" />
      <el-table-column label="合作方名称" align="center" prop="hzfmc" />
      <el-table-column label="合作方简称" align="center" prop="hzfjc" />
      <el-table-column label="统一社会信用代码" align="center" prop="tyshxydm" />
      <el-table-column label="合作方地址" align="center" prop="hzfdz" />
      <el-table-column label="合作方联系人" align="center" prop="hzflxr" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:cooperManage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:cooperManage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改合作单位管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="公司代码" prop="xxdm">
          <el-input v-model="form.xxdm" placeholder="请输入公司代码" />
        </el-form-item>
        <el-form-item label="公司名称" prop="xxmc">
          <el-input v-model="form.xxmc" placeholder="请输入公司名称" />
        </el-form-item>
        <el-form-item label="合作方电话" prop="hzfdh">
          <el-input v-model="form.hzfdh" placeholder="请输入合作方电话" />
        </el-form-item>
        <el-form-item label="合作方税号" prop="hzfsh">
          <el-input v-model="form.hzfsh" placeholder="请输入合作方税号" />
        </el-form-item>
        <el-form-item label="合作方开户行" prop="hzfkhx">
          <el-input v-model="form.hzfkhx" placeholder="请输入合作方开户行" />
        </el-form-item>
        <el-form-item label="合作方账号" prop="hzfzh">
          <el-input v-model="form.hzfzh" placeholder="请输入合作方账号" />
        </el-form-item>
        <el-form-item label="邮编" prop="yb">
          <el-input v-model="form.yb" placeholder="请输入邮编" />
        </el-form-item>
        <el-form-item label="合作方服务人员" prop="hzffwry">
          <el-input v-model="form.hzffwry" placeholder="请输入合作方服务人员" />
        </el-form-item>
        <el-form-item label="建档日期" prop="jdrq">
          <el-date-picker clearable
                          v-model="form.jdrq"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择建档日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合作方合同/协议" prop="hzfht">
          <el-input v-model="form.hzfht" placeholder="请输入合作方合同/协议" />
        </el-form-item>
        <el-form-item label="主要内容" prop="zynr">
          <el-input v-model="form.zynr" placeholder="请输入主要内容" />
        </el-form-item>
        <el-form-item label="合同情况" prop="htqk">
          <el-input v-model="form.htqk" placeholder="请输入合同情况" />
        </el-form-item>
        <el-form-item label="合作方类别" prop="hzflb">
          <el-input v-model="form.hzflb" placeholder="请输入合作方类别" />
        </el-form-item>
        <el-form-item label="合同变更情况及附件" prop="htbgqkjfj">
          <el-input v-model="form.htbgqkjfj" placeholder="请输入合同变更情况及附件" />
        </el-form-item>
        <el-form-item label="合作项目编号" prop="hzxmbh">
          <el-input v-model="form.hzxmbh" placeholder="请输入合作项目编号" />
        </el-form-item>
        <el-form-item label="合作项目名称" prop="hzxmmc">
          <el-input v-model="form.hzxmmc" placeholder="请输入合作项目名称" />
        </el-form-item>
        <el-form-item label="合作方资金往来类别" prop="hzfzjwllb">
          <el-input v-model="form.hzfzjwllb" placeholder="请输入合作方资金往来类别" />
        </el-form-item>
        <el-form-item label="资金金额" prop="zjje">
          <el-input v-model="form.zjje" placeholder="请输入资金金额" />
        </el-form-item>
        <el-form-item label="经办人" prop="jbr">
          <el-input v-model="form.jbr" placeholder="请输入经办人" />
        </el-form-item>
        <el-form-item label="创建人" prop="cjr">
          <el-input v-model="form.cjr" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="创建日期" prop="cjrq">
          <el-date-picker clearable
                          v-model="form.cjrq"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择创建日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改人" prop="xgr">
          <el-input v-model="form.xgr" placeholder="请输入修改人" />
        </el-form-item>
        <el-form-item label="合作方类型" prop="hzflx">
          <el-input v-model="form.hzflx" placeholder="请输入合作方类型" />
        </el-form-item>
        <el-form-item label="修改日期" prop="xgrq">
          <el-date-picker clearable
                          v-model="form.xgrq"
                          type="datetime"
                          value-format="yyyy-MM-dd HH:mm:ss"
                          placeholder="请选择修改日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合作方代码" prop="hzfdm">
          <el-input v-model="form.hzfdm" placeholder="请输入合作方代码" />
        </el-form-item>
        <el-form-item label="合作方名称" prop="hzfmc">
          <el-input v-model="form.hzfmc" placeholder="请输入合作方名称" />
        </el-form-item>
        <el-form-item label="合作方简称" prop="hzfjc">
          <el-input v-model="form.hzfjc" placeholder="请输入合作方简称" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="tyshxydm">
          <el-input v-model="form.tyshxydm" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="合作方地址" prop="hzfdz">
          <el-input v-model="form.hzfdz" placeholder="请输入合作方地址" />
        </el-form-item>
        <el-form-item label="合作方联系人" prop="hzflxr">
          <el-input v-model="form.hzflxr" placeholder="请输入合作方联系人" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listCooperManage, getCooperManage, delCooperManage, addCooperManage, updateCooperManage } from "@/api/pm/cooperManage";

  export default {
    name: "CooperManage",
    data() {
      return {
        // 按钮loading
        buttonLoading: false,
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 合作单位管理表格数据
        cooperManageList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          xxdm: undefined,
          xxmc: undefined,
          hzfdh: undefined,
          hzfsh: undefined,
          hzfkhx: undefined,
          hzfzh: undefined,
          yb: undefined,
          hzffwry: undefined,
          jdrq: undefined,
          hzfht: undefined,
          zynr: undefined,
          htqk: undefined,
          hzflb: undefined,
          htbgqkjfj: undefined,
          hzxmbh: undefined,
          hzxmmc: undefined,
          hzfzjwllb: undefined,
          zjje: undefined,
          jbr: undefined,
          cjr: undefined,
          cjrq: undefined,
          xgr: undefined,
          hzflx: undefined,
          xgrq: undefined,
          hzfdm: undefined,
          hzfmc: undefined,
          hzfjc: undefined,
          tyshxydm: undefined,
          hzfdz: undefined,
          hzflxr: undefined
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          id: [
            { required: true, message: "主键不能为空", trigger: "blur" }
          ],
          xxdm: [
            { required: true, message: "公司代码不能为空", trigger: "blur" }
          ],
          xxmc: [
            { required: true, message: "公司名称不能为空", trigger: "blur" }
          ],
          hzfdh: [
            { required: true, message: "合作方电话不能为空", trigger: "blur" }
          ],
          hzfsh: [
            { required: true, message: "合作方税号不能为空", trigger: "blur" }
          ],
          hzfkhx: [
            { required: true, message: "合作方开户行不能为空", trigger: "blur" }
          ],
          hzfzh: [
            { required: true, message: "合作方账号不能为空", trigger: "blur" }
          ],
          yb: [
            { required: true, message: "邮编不能为空", trigger: "blur" }
          ],
          hzffwry: [
            { required: true, message: "合作方服务人员不能为空", trigger: "blur" }
          ],
          jdrq: [
            { required: true, message: "建档日期不能为空", trigger: "blur" }
          ],
          hzfht: [
            { required: true, message: "合作方合同/协议不能为空", trigger: "blur" }
          ],
          zynr: [
            { required: true, message: "主要内容不能为空", trigger: "blur" }
          ],
          htqk: [
            { required: true, message: "合同情况不能为空", trigger: "blur" }
          ],
          hzflb: [
            { required: true, message: "合作方类别不能为空", trigger: "blur" }
          ],
          htbgqkjfj: [
            { required: true, message: "合同变更情况及附件不能为空", trigger: "blur" }
          ],
          hzxmbh: [
            { required: true, message: "合作项目编号不能为空", trigger: "blur" }
          ],
          hzxmmc: [
            { required: true, message: "合作项目名称不能为空", trigger: "blur" }
          ],
          hzfzjwllb: [
            { required: true, message: "合作方资金往来类别不能为空", trigger: "blur" }
          ],
          zjje: [
            { required: true, message: "资金金额不能为空", trigger: "blur" }
          ],
          jbr: [
            { required: true, message: "经办人不能为空", trigger: "blur" }
          ],
          cjr: [
            { required: true, message: "创建人不能为空", trigger: "blur" }
          ],
          cjrq: [
            { required: true, message: "创建日期不能为空", trigger: "blur" }
          ],
          xgr: [
            { required: true, message: "修改人不能为空", trigger: "blur" }
          ],
          hzflx: [
            { required: true, message: "合作方类型不能为空", trigger: "blur" }
          ],
          xgrq: [
            { required: true, message: "修改日期不能为空", trigger: "blur" }
          ],
          hzfdm: [
            { required: true, message: "合作方代码不能为空", trigger: "blur" }
          ],
          hzfmc: [
            { required: true, message: "合作方名称不能为空", trigger: "blur" }
          ],
          hzfjc: [
            { required: true, message: "合作方简称不能为空", trigger: "blur" }
          ],
          tyshxydm: [
            { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
          ],
          hzfdz: [
            { required: true, message: "合作方地址不能为空", trigger: "blur" }
          ],
          hzflxr: [
            { required: true, message: "合作方联系人不能为空", trigger: "blur" }
          ]
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 查询合作单位管理列表 */
      getList() {
        this.loading = true;
        listCooperManage(this.queryParams).then(response => {
          this.cooperManageList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: undefined,
          xxdm: undefined,
          xxmc: undefined,
          hzfdh: undefined,
          hzfsh: undefined,
          hzfkhx: undefined,
          hzfzh: undefined,
          yb: undefined,
          hzffwry: undefined,
          jdrq: undefined,
          hzfht: undefined,
          zynr: undefined,
          htqk: undefined,
          hzflb: undefined,
          htbgqkjfj: undefined,
          hzxmbh: undefined,
          hzxmmc: undefined,
          hzfzjwllb: undefined,
          zjje: undefined,
          jbr: undefined,
          cjr: undefined,
          cjrq: undefined,
          xgr: undefined,
          hzflx: undefined,
          xgrq: undefined,
          hzfdm: undefined,
          hzfmc: undefined,
          hzfjc: undefined,
          tyshxydm: undefined,
          hzfdz: undefined,
          hzflxr: undefined
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加合作单位管理";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.loading = true;
        this.reset();
        const id = row.id || this.ids
        getCooperManage(id).then(response => {
          this.loading = false;
          this.form = response.data;
          this.open = true;
          this.title = "修改合作单位管理";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            this.buttonLoading = true;
            if (this.form.id != null) {
              updateCooperManage(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            } else {
              addCooperManage(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }).finally(() => {
                this.buttonLoading = false;
              });
            }
          }
        });
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        this.$modal.confirm('是否确认删除合作单位管理编号为"' + ids + '"的数据项？').then(() => {
          this.loading = true;
          return delCooperManage(ids);
        }).then(() => {
          this.loading = false;
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {
        }).finally(() => {
          this.loading = false;
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('business/cooperManage/export', {
          ...this.queryParams
        }, `cooperManage_${new Date().getTime()}.xlsx`)
      }
    }
  };
</script>
